package com.downbox.controller;

import com.downbox.dto.HistoryItemDTO;
import com.downbox.dto.PageResp;
import com.downbox.dto.R;
import com.downbox.security.UserContext;
import com.downbox.service.ContentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 历史记录控制器
 */
@RestController
@RequestMapping("/history")
@Tag(name = "历史记录相关接口")
public class HistoryController {

    @Autowired
    private ContentService contentService;

    @GetMapping({"", "/draws"})
    @Operation(summary = "获取抽奖历史记录")
    public R<PageResp<HistoryItemDTO>> getDrawHistory(
            @RequestParam(required = false) String type,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int size) {
        Long userId = UserContext.getUserId();
        PageResp<HistoryItemDTO> history = contentService.getDrawHistory(userId, type, page, size);
        return R.success(history);
    }
}